#include "minitrain.h"
#include "ui_minitrain.h"

MiniTrain::MiniTrain(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MiniTrain)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);
    m_lSaloonTypes<<"Tc1"<<"Mp1"<<"M1"<<"M2"<<"Mp2"<<"Tc2";
    initSaloons();
}

MiniTrain::~MiniTrain()
{
    delete ui;
}

void MiniTrain::initSaloons()
{
    m_nSaloonWidth = MiniCarSaloonWidth;
    m_nSaloonHeight = this->height() - MiniCarTopSpace_1220 - MiniCarBottomSpace_1220;

    uint wheelspace = (m_nSaloonWidth - 4*MiniCarWheelSize_1220)/3;

    for(int i=0;i<SaloonCnt;i++)
    {
        QLabel *saloon = new QLabel(this);
        saloon->setStyleSheet(MiniSaloonStyle);
        saloon->setAlignment(Qt::AlignCenter);
        saloon->setText(m_lSaloonTypes.at(i));
        saloon->setGeometry(MiniCarLeftSpace_1220+(m_nSaloonWidth+MiniCarHSpace_1220)*i,MiniCarTopSpace_1220,
                            m_nSaloonWidth,m_nSaloonHeight);
        for(int j=0;j<4;j++)
        {
            QLabel *saloonwheel = new QLabel(this);
            if((i==0 || i==SaloonCnt-1))
                saloonwheel->setStyleSheet(MiniUnTracWheelStyle);
            else
               saloonwheel->setStyleSheet(MiniTracWheelStyle);
            saloonwheel->setGeometry(MiniCarLeftSpace_1220+wheelspace+(m_nSaloonWidth+MiniCarHSpace_1220)*i+(j%2)*MiniCarWheelSize_1220+(j/2)*(wheelspace+2*MiniCarWheelSize_1220),
                                MiniCarTopSpace_1220+m_nSaloonHeight,
                                MiniCarWheelSize_1220,MiniCarWheelSize_1220);
        }
    }
}
